package com.zheng.StudentManagement;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentTollClass {
    public static final Scanner INPUT=new Scanner(System.in);
    private StudentTollClass(){}
    //打印菜单
    static void studentShow(){
        System.out.println("-----------欢迎来到学生管理系统--------------");
        System.out.println("1.添加学生");
        System.out.println("2.删除学生");
        System.out.println("3.修改学生");
        System.out.println("4.查看所有学生");
        System.out.println("5.退出");
        System.out.println("------------------------------------------");
        System.out.println("请输入你的选择");
    }

    //添加学生
    static void addStudent(ArrayList<Student> list){

        Student s=new Student();
        System.out.println("请输入学生的学号");
        String sid=INPUT.next();
        if (list.size()!=0){
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getSid().equals(sid)){
                    System.out.println("学号重复！！！");
                    return;
                }
            }
        }
        s.setSid(sid);
        System.out.println("请输入学生的姓名");
        s.setName(INPUT.next());
        System.out.println("请输入学生的年龄");
        s.setAge(INPUT.nextInt());
        System.out.println("请输入学生的居住地");
        s.setBirthday(INPUT.next());
        list.add(s);
        showAllStudent(list);
    }

    //查看所有学生
    static void showAllStudent(ArrayList<Student> list){
        for (Student student : list) {
            System.out.println(student);
        }
    }

    //删除学生
    static void deleteStudent(ArrayList<Student> list){
        System.out.println("请输入你要删除的学生的学号");
        String deleteId=INPUT.next();
        for (int i = 0; i < list.size(); i++) {
            if (deleteId.equals(list.get(i).getSid())){
                list.remove(i);
            }else {
                System.out.println("该信息不存在，请重新输入！");
            }
        }
        showAllStudent(list);
    }

    //修改学生
    static void upDateStudent(ArrayList<Student> list){
        System.out.println("请输入你要修改的学生的学号");
        String deleteId=INPUT.next();
        Student stu=null;
        for (int i = 0; i < list.size(); i++) {
            if (deleteId.equals(list.get(i).getSid())){
                stu=list.get(i);
                System.out.println("请输入学生的姓名");
                stu.setName(INPUT.next());
                System.out.println("请输入学生的年龄");
                stu.setAge(INPUT.nextInt());
                System.out.println("请输入学生的居住地");
                stu.setBirthday(INPUT.next());
            }else {
                System.out.println("该信息不存在，请重新输入！");
            }
        }
        showAllStudent(list);
    }

    //开始
    static void start(ArrayList<Student> list) {
        out:
        while (true){
            //打印菜单
            StudentTollClass.studentShow();
            int count=INPUT.nextInt();
            switch (count){
                case 1:
                    //添加学生
                    StudentTollClass.addStudent(list);
                    break;
                case 2:
                    //删除学生
                    StudentTollClass.deleteStudent(list);
                    break;
                case 3:
                    //修改学生信息
                    StudentTollClass.upDateStudent(list);
                    break;
                case 4:
                    //查看学生对象
                    StudentTollClass.showAllStudent(list);
                    break;
                case 5:
                    break out;
                default:
                    System.out.println("输入错误！");
                    break;
            }
        }
    }
}
